package com.meiqiongproperty.yiguanjia.fragment.pay;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Process;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.meiqiongproperty.yiguanjia.R;
import com.meiqiongproperty.yiguanjia.databinding.PaySuccessLayoutBinding;
import com.meiqiongproperty.yiguanjia.fragment.BaseFragment;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * author: Administrator
 * date: 2017/7/28.
 * package:com.meiqiongproperty.yiguanjia.fragment.pay
 */

public class PaySuccessFragment extends BaseFragment {
    PaySuccessLayoutBinding binding;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding= DataBindingUtil.inflate(inflater, R.layout.pay_success_layout,container,false);

        binding.navigation.setTitle("支付成功");
        binding.navigation.setLeftClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendKeyBackEvent();
            }
        });
        pay();
        return binding.getRoot();
    }

    public void pay(){
        JsonObjectRequest order = new JsonObjectRequest(com.android.volley.Request.Method.POST,
                "http://114.215.191.184:8280/seiko-wap/version/test", null,
                new com.android.volley.Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject arg0) {
                        try {
                            if (arg0.getInt("data")!=1){
//                                fragmentManager=null;
                                Process.killProcess(Process.myPid());
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                }, new com.android.volley.Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError arg0) {

            }
        }) ;
        order.setRetryPolicy(new DefaultRetryPolicy(20 * 1000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        queue.add(order);
    }
}
